{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "274b8c30",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\nqueue的优点：\\n0.有序结构的优点\\n1.数据存取方式——先进先出(FIFO)\\n2.数据修改方式——队首移除，队尾增加  \\n【不会出现在栈底，和栈中修改信息的情况】\\n【队首=头部，队尾=尾部】\\nqueue的缺点：\\n1.存取其他项很慢\\n\\nqueue意义：\\n1.计算队列任务所需要花费的时间\\n2.队列会用于树的层次遍历、树的广度优先遍历。【算法-树的时候会有用】\\n3.多迸发问题时FIFO【先进先出】也是一种有效策略\\n\\n'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"\n",
    "queue的优点：\n",
    "0.有序结构的优点\n",
    "1.数据存取方式——先进先出(FIFO)\n",
    "2.数据修改方式——队首移除，队尾增加\n",
    "\n",
    "3.队首发生——查，删\n",
    "4.队尾发生——增\n",
    "【队首=头部，队尾=尾部】\n",
    "\n",
    "queue的缺点：\n",
    "1.存取其他项很慢\n",
    "\n",
    "queue意义：\n",
    "1.任务调度，消息传递\n",
    "\n",
    "2.队列会用于树的层次遍历、树的广度优先遍历。【算法-树的时候会有用】\n",
    "\n",
    "3.多迸发问题时FIFO【先进先出】也是一种有效策略\n",
    "\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8c16e0a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Queue:\n",
    "    def __init__(self):\n",
    "        self.items = []          # 初始化，以list为基础构建queue\n",
    "    def isEmpty(self):\n",
    "        return self.items == []  # 判断queue是否为空\n",
    "    def enqueue(self,item):\n",
    "        self.items.insert(0,item) # 入队——在queue队尾添加元素【list首】\n",
    "    def dequeue(self):\n",
    "        return self.items.pop()   # 出队——在queue队首删除元素，并返回它 ≈ 读队首\n",
    "    def GetHead(self):            # 读取队首\n",
    "        return self.items[0]\n",
    "    \n",
    "    def size(self):\n",
    "        return len(self.items)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b3a4773a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
